package spring.cloud.tasks.tasks_assign_manager.database.service.impl;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;
import spring.cloud.tasks.tasks_assign_manager.database.entity.NameSpaceZooKeeperClusterMappingDto;
import spring.cloud.tasks.tasks_assign_manager.database.repository.NameSpaceZooKeeperClusterMappingDtoRepository;
import spring.cloud.tasks.tasks_assign_manager.database.service.NameSpaceZooKeeperClusterMappingDtoService;

import java.util.ArrayList;
import java.util.Iterator;
import java.util.List;


@Service
public class NameSpaceZooKeeperClusterMappingDtoServiceImpl implements NameSpaceZooKeeperClusterMappingDtoService {

    @Autowired
    private NameSpaceZooKeeperClusterMappingDtoRepository nameSpaceZooKeeperClusterMappingDtoRepository;

    private List<NameSpaceZooKeeperClusterMappingDto> getActivenameSpaceZooKeeperClusterMappingDtoList(List<NameSpaceZooKeeperClusterMappingDto> dtoList) {
        List<NameSpaceZooKeeperClusterMappingDto> list = new ArrayList<NameSpaceZooKeeperClusterMappingDto>();
        if (dtoList != null) {
            Iterator<NameSpaceZooKeeperClusterMappingDto> iterator = dtoList.iterator();
            while (iterator.hasNext()) {
                NameSpaceZooKeeperClusterMappingDto next = iterator.next();
                if (next.getIsDeleted() == 0) {
                    list.add(next);
                }
            }
        }
        return list;
    }


    @Transactional(readOnly = true)
    @Override
    public List<NameSpaceZooKeeperClusterMappingDto> getNameSpaceZooKeeperClusterMappingDtoList(String zooKeeperClusterKey) {
        return getActivenameSpaceZooKeeperClusterMappingDtoList(nameSpaceZooKeeperClusterMappingDtoRepository.selectByZooKeeperClusterKey(zooKeeperClusterKey));
    }


}
